<template>
  <div>
  <el-form :model="Form"
  :rules='rules'
  status-icon
  ref="ruleForm"
  >
   <el-form-item label="账号" prop="username">
    <el-input v-model="Form.username"></el-input>
        </el-form-item>
     <el-form-item label="密码" prop="password">
 
    <el-input v-model="Form.password"></el-input>
      </el-form-item>
       <el-form-item>
    <el-button type="primary" @click="submitForm">登录</el-button>
    <el-button @click="resetForm">重置</el-button>
  </el-form-item>
  </el-form>
  </div>
</template>

<script>
import Mock from 'mockjs'
import {getMenu} from '../../api/data'
export default {
data() {
    return {
        Form:{
            username:'admin',
            password:'admin'

        },
        rules:{
       username:[{ required: true, message: '请输入账号', trigger: 'blur' },
             { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }],
       password:[{ required: true, message: '请输入密码', trigger: 'blur' },
                 { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
       ],
        },

    }
},
 methods: {
      submitForm() {
        this.$refs.ruleForm.validate( async(valid) => {
          if (valid) {
        const res= await getMenu(this.Form)
        console.log(res)
        this.$store.commit('clearMune')
        this.$store.commit('setMune',res.data.menu)

       this.$store.commit('setToken',res.data.token)
       this.$store.commit('addMune',this.$router)
       
      console.log(this.$store.state.tab.mune)
      console.log('this.$router',this.$router)
       this.$router.push('/')
    //    console.log(token)
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm() {
        this.$refs.ruleForm.resetFields();
      },
       getmenu(){
      this.$store.commit('setMune')
    }
    }
}
</script>

<style scoped>
.el-form{
    width: 600px;
    height: 400px;
  
    text-align: center;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
}
</style>